package com.woniu.mgr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.mgr.controller.form.CoachModifyForm;
import com.woniu.mgr.model.Coach;
import com.woniu.mgr.dao.CoachDao;
import com.woniu.mgr.model.VenueApply;
import com.woniu.mgr.service.CoachService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.mgr.util.BeanCopyUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 教练特有信息表 服务实现类
 * </p>
 *
 * @author Silas
 * @since 2023-02-15
 */
@Service
public class CoachServiceImpl extends ServiceImpl<CoachDao, Coach> implements CoachService {

    @Resource
    private CoachDao coachDao;

    @Override
    public IPage<Coach> list(Integer page, Integer size) {
        //分页查询
        Page<Coach> pages = new Page<>(page, size);
        QueryWrapper<Coach> wrapper = new QueryWrapper<>();
        Page<Coach> page1 = coachDao.selectPage(pages, wrapper);
        return page1;
    }

    @Override
    public void coachModify(CoachModifyForm coachModifyForm) {
        //修改教练信息
        Coach coach = BeanCopyUtil.copyObject(coachModifyForm, Coach.class);
        updateById(coach);
    }

    @Override
    public void beCoach(Coach coach) {
        save(coach);
    }

    @Override
    public IPage<Coach> query(String condition, Integer page, Integer size) {
        Page<Coach> pages = new Page<>(page, size);
        QueryWrapper<Coach> queryWrapper = new QueryWrapper<>();
        if (!"".equals(condition) || condition != null) {
            queryWrapper.eq("realname", condition)
                    .or().eq("style", condition)
                    .or().like("venue_name", condition)
                    .or().like("introduce", condition);
        }
        IPage<Coach> coachPage = baseMapper.selectPage(pages, queryWrapper);
        return coachPage;
    }
}
